package top.rainf.support;

import lombok.ToString;
import org.springframework.web.bind.annotation.ResponseBody;
import top.rainf.domain.dto.AreaWithBlocks;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @author 星环
 * @date 2023/5/8 9:11:23
 * @description 结果类，用于返回数据，以及简单的信息提示
 */
@ToString
public class Result {
    public static final int SUCCEED = 0;
    public static final int FAILED = -1;
    private int code;
    private String msg;
    private Map<String ,Object> data;

    public Result(int code, String msg, Map<String, Object> data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = new HashMap<>();
    }

    public Result(int code) {
        this.code = code;
    }

    /**
     * 请求数据成功，数据用addObj添加
     * @param msg 提示信息
     * @return
     */
    public static Result success(String msg){
        return new Result(SUCCEED,msg);
    }

    /**
     * 查询成功，默认msg设置
     * @return
     */
    public static Result success(){
        return success("请求成功");
    }

    public static Result success(String key,Object oneData){
        return success().addObj(key,oneData);
    }
    public static Result fail(){
        return new Result(FAILED);
    }
    public static Result fail(String s) {
        return new Result(FAILED,s);
    }

    public Result addObj(String key,Object value){
        data.put(key,value);
        return this;
    }
    //
    //public Result addObjs(String key, List<Object> objs){
    //    data.putAll(objs.stream().map());
    //}

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }


}
